﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MaxLeaf.Platform.DataContract;
using CommonsLib.DB;
using MaxLeaf.Platform.DALImplementation;
using MaxLeaf.Platform.Functions;
using CommonsLib.Utility;
using MaxLeaf.Platform.Commons;
using MaxLeaf.Platform.Contract;
using System.Transactions;
namespace MaxLeaf.Platform.BLLImplementation
{
    public class imStoresReqHdrApproProcessor
    {
        public bool InitPoReqHdr( poReqHdrDataModel poReqModel )
        {
            using (DBAccess dbcon = new DBAccess(DataFunc.GetConnectionInfo(Const.DB_SCPSEOrder)))
            {
                if (!new poReqHdrDAL().CheckHdrExist(dbcon, poReqModel))
                {
                    poReqModel = (poReqHdrDataModel)new BaseBLL(typeof(poReqHdrDataModel).ToString()).InsertFinterID(poReqModel);
                    new BaseBLL().Add(poReqModel);
                }

                return true;
            }
        }

        public bool InitImStoreOutHdr( imStoresReqHdrDataModel imStoresReqHdrModel, imStoresOutputHdrDataModel imStoreOutModel)
        {
            using (DBAccess dbcon = new DBAccess(DataFunc.GetConnectionInfo(Const.DB_SCPSEOrder)))
            {

                #region 获得新的出库单的FinterID  和  DocNo
                imStoreOutModel = (imStoresOutputHdrDataModel)new BaseBLL(typeof(imStoresOutputHdrDataModel).ToString()).InsertFinterID(imStoreOutModel);

                imStoresOutputHdrDataModel imStoreOutModel_New = new imStoresOutputHdrDataModel(imStoreOutModel.CompanyID, imStoresReqHdrModel.DepartID, imStoreOutModel.Key, imStoreOutModel.OrdNo, imStoresReqHdrModel.EnterUserID);
                imStoreOutModel = (imStoresOutputHdrDataModel)new BaseBLL(typeof(imStoresOutputHdrDataModel).ToString()).Add(imStoreOutModel);

                InitImStoreOutDtl(imStoresReqHdrModel);
                #endregion
                
                return true;
            }
        }

        public bool InitImStoreOutDtl(imStoresReqHdrDataModel imStoresReqHdrModel)
        {
            imStoresReqDtlDataModel imDtlModel = new imStoresReqDtlDataModel();
            List<Object> imStoreReqDtl = (List<Object>)BaseBLL.GetDataModelBLL("imStoresReqDtlDataModel").SelectDtl(imDtlModel, imStoresReqHdrModel.Key);
            for (int i = 0; i <= imStoreReqDtl.Count; i++)
            {
                imStoresOutputDtlDataModel imStoresDataModel = new imStoresOutputDtlDataModel();
                imStoresDataModel = (imStoresOutputDtlDataModel)new imStoresOutputDtlBLL().InsertFinterID(imStoresDataModel);
                imStoresOutputHdrDAL imDAL = new imStoresOutputHdrDAL();
                imDAL.InitStoreOutDtl(imStoresDataModel);
            }
            return true;
        }

        public bool InitPoReqDtl(poReqHdrDataModel poReqModel)
        {
            return true;
        }
    }
}
